{include file="public/_meta" title="备份列表"/}
<style>
    .loader {
        position: fixed;
        left: 40%;
        top: 40%;
        width: 100px;
        height: 100px;
        z-index: 9999;
    }
</style>
    <nav class="breadcrumb"> <a href="javascript:void(0);">首页</a>
        <span class="c-gray en">&gt;</span>
        <a href="javascript:void(0);">备份管理</a>
        <span class="c-gray en">&gt;</span>
        <a href="javascript:void(0);">备份列表</a>
    </nav>
    <div class="Hui-article">
        <article class="cl pd-20">
            <div class="cl pd-5 bg-1 bk-gray mt-20">
                <span class="r">共有数据：<strong>{$count}</strong> 条</span>
                <input onclick="backup()" class="btn btn-success size-S radius btn6 mr10" value="备份数据表" type="submit">
                <input onclick="batch_repair()" class="btn btn-success size-S radius btn6 mr10" value="修复数据表" type="submit">
                <input onclick="batch_optimize()" class="btn btn-success size-S radius btn6 mr10" value="优化数据表" type="submit">&nbsp;
                系统默认备份目录：<b>__PUBLIC__/backup</b>
            </div>
            <div class="cl pd-20">
            <form action="" method="post" class="form form-horizontal" enctype="multipart/form-data">
            <table class="table table-border table-bordered table-bg table-sort">
                <thead>
                <tr>
                    <th scope="col" colspan="12"><center>数据库信息列表</center></th>
                </tr>
                <tr class="text-c">
                    <th width="25"><input type="checkbox" name="" value=""></th>
                    <th>数据库表名</th>
                    <th>数据库类型</th>
                    <th>记录数</th>
                    <th>数据</th>
                    <th>索引</th>
                    <th>碎片</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                {volist name="res" id="vo"}
                    <tr class="text-c">
                        <td><input type="checkbox" name="table[]" value="{$vo.Name}" type="checkbox"></td>
                        <td>{$vo.Name}</td>
                        <td>{$vo.Engine}</td>
                        <td>{$vo.Rows}</td>
                        <td>{$vo.Data_length}</td>
                        <td>{$vo.Index_length}</td>
                        <td>{$vo.Data_free}</td>
                        <td class="td-manage">
                            <a title="修复表" onclick="repair(this,'{$vo.Name}')" class="btn btn-success size-S radius" style="text-decoration:none">修复表</a>&nbsp;
                            <a title="优化表" onclick="optimize(this,'{$vo.Name}')" class="btn btn-success size-S radius" style="text-decoration:none">优化表</a>
                        </td>
                    </tr>
                {/volist}
                </tbody>
            </table>
                <div id="loadImage"></div>
                <div style="text-align: center;">
                </div>
            </form>
            </div>
        </article>

    </div>
    <!--_footer 作为公共模版分离出去-->
    {include file="public/_footer" /}
    <!--/_footer 作为公共模版分离出去-->

    <!--请在下方写此页面业务相关的脚本-->
    <script>
        $(".table-sort").dataTable({
            "aaSorting": [[ 1, "asc" ]],//默认第几个排序
            "bStateSave": true,//状态保存
            "aoColumnDefs": [
                //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
                {"orderable":false,"aTargets":[0,7]}// 制定列不参与排序
            ]
        });

        //数据备份
        function backup(){
            load();
            var table =[];

            $('input[name="table[]"]:checked').each(function(){
                table.push($(this).val());
            });
            $.ajax({
                type: 'post',
                url: "{:url('Database/backup')}",
                dataType: 'json',
                data: {table:table,id:1},
                success: function(msg){
                    if(msg){
                        $('#loading').remove();
                    }
                    if(msg.status == false){
                        layer.msg(msg.message,{icon: 5,time:2000});
                    }else if(msg.status == true){
                        layer.msg(msg.message,{icon: 6,time:1000});
                        setTimeout(jump,1000);
                        function jump(){
                            window.location.reload();
                        }
                    }
                }
            });
        }

        //备份加载
        function load(){
            $('#loadImage').append('<div id="loading" class="loader"><img src="__PUBLIC__/admin/images/load.gif"/></div>');
        }

        //优化表
        function optimize(obj,table){
            $.ajax({
                type: 'get',
                url: "{:url('Database/optimize')}",
                dataType: 'json',
                data: {table:table},
                success: function(msg){
                    if(msg.status == false){
                        layer.msg(msg.message,{icon: 5,time:2000});
                    }else if(msg.status == true){
                        layer.msg(msg.message,{icon: 6,time:1000});
                        setTimeout(jump,1000);
                        function jump(){
                            window.location.reload();
                        }
                    }
                },
            });
        }

        //修复表
        function repair(obj,table){
            $.ajax({
                type: 'get',
                url: "{:url('Database/repair')}",
                dataType: 'json',
                data: {table:table},
                success: function(msg){
                    if(msg.status == false){
                        layer.msg(msg.message,{icon: 5,time:2000});
                    }else if(msg.status == true){
                        layer.msg(msg.message,{icon: 6,time:1000});
                        setTimeout(jump,1000);
                        function jump(){
                            window.location.reload();
                        }
                    }
                },
            });
        }

        //批量优化表
        function batch_optimize(){
            var table =[];

            $('input[name="table[]"]:checked').each(function(){
                table.push($(this).val());
            });

            if(table.length == false){
                layer.msg('请选择要优化的数据表',{icon:2,time:2000});
                return;
            }
            $.ajax({
                type: 'post',
                url: "{:url('Database/optimize')}",
                dataType: 'json',
                data: {table:table},
                success: function(msg){
                    if(msg.status == false){
                        layer.msg(msg.message,{icon: 5,time:2000});
                    }else if(msg.status == true){
                        layer.msg(msg.message,{icon: 6,time:1000});
                        setTimeout(jump,1000);
                        function jump(){
                            window.location.reload();
                        }
                    }
                },
            });
        }

        //批量修复表
        function batch_repair(){
            var table =[];

            $('input[name="table[]"]:checked').each(function(){
                table.push($(this).val());
            });

            if(table.length == false){
                layer.msg('请选择要修复的数据表',{icon:2,time:2000});
                return;
            }
            $.ajax({
                type: 'post',
                url: "{:url('Database/repair')}",
                dataType: 'json',
                data: {table:table},
                success: function(msg){
                    if(msg.status == false){
                        layer.msg(msg.message,{icon: 5,time:2000});
                    }else if(msg.status == true){
                        layer.msg(msg.message,{icon: 6,time:1000});
                        setTimeout(jump,1000);
                        function jump(){
                            window.location.reload();
                        }
                    }
                },
            });
        }
    </script>
